<!-- app/templates/index.html -->
{% extends 'base.html' %}

{% block title %}主页 - DCO Webhook{% endblock %}

{% block content %}
    <div class="flex justify-between items-center mb-6">
        <h1 class="text-2xl font-semibold">DCO Webhook 数据查询</h1>
        <a href="{{ url_for('view_events') }}" class="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded">高级筛选</a>
    </div>
    <form method="get" action="{{ url_for('index') }}" class="mb-6">
        <div class="flex">
            <input type="text" name="query" placeholder="输入仓库名称或 Pusher" value="{{ request.query_params.get('query', '') }}" class="w-full px-4 py-2 border rounded-l-md focus:outline-none focus:ring-2 focus:ring-blue-400">
            <button type="submit" class="bg-green-500 hover:bg-green-700 text-white font-bold py-2 px-4 rounded-r-md">查询</button>
        </div>
    </form>

    {% if events %}
        <div class="overflow-x-auto">
            <table class="min-w-full bg-white">
                <thead>
                    <tr>
                        <th class="py-2 px-4 border-b">ID</th>
                        <th class="py-2 px-4 border-b">仓库</th>
                        <th class="py-2 px-4 border-b">所有者</th>
                        <th class="py-2 px-4 border-b">Pusher</th>
                        <th class="py-2 px-4 border-b">Ref</th>
                        <th class="py-2 px-4 border-b">Before SHA</th>
                        <th class="py-2 px-4 border-b">After SHA</th>
                        <th class="py-2 px-4 border-b">接收时间</th>
                    </tr>
                </thead>
                <tbody>
                    {% for event in events %}
                        <tr class="text-center">
                            <td class="py-2 px-4 border-b">{{ event.id }}</td>
                            <td class="py-2 px-4 border-b">{{ event.repository_name }}</td>
                            <td class="py-2 px-4 border-b">{{ event.repository_owner }}</td>
                            <td class="py-2 px-4 border-b">{{ event.pusher }}</td>
                            <td class="py-2 px-4 border-b">{{ event.ref }}</td>
                            <td class="py-2 px-4 border-b"><code>{{ event.before_sha[:7] }}</code></td>
                            <td class="py-2 px-4 border-b"><code>{{ event.after_sha[:7] }}</code></td>
                            <td class="py-2 px-4 border-b">{{ event.received_at.strftime('%Y-%m-%d %H:%M:%S') }}</td>
                        </tr>
                    {% endfor %}
                </tbody>
            </table>
        </div>
    {% else %}
        <div class="bg-yellow-100 border border-yellow-400 text-yellow-700 px-4 py-3 rounded relative" role="alert">
            <span class="block sm:inline">没有找到相关数据。</span>
        </div>
    {% endif %}
{% endblock %}
